﻿// Sheego.Service.X400
// Copyright(C) 2015 Schwab Versand GmbH
//
// This source file is subject to the Microsoft Public License(Ms-PL).
// http://www.opensource.org/licenses/ms-pl.html
// All other rights reserved.
using Sheego.Service.X400.Job.Shared.BO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sheego.Service.X400.Job.Impl.BO
{
    class X400Address : IX400Address
    {
        #region IX400Address Members

        public string Surname { get;set; }

        public string Organizationname { get; set; }

        public string Administrationmanagementdomain { get; set; }

        public string Countryname { get; set; }

        public String Givenname { get; set; }

        public String OrganizationalUnitnames { get; set; }

        public String Initials { get; set; }

        public string FREEFORM { get; set; }

        public String DDA_RFC_822 { get; set; }

        public override string ToString()
        {
            var builder = new StringBuilder();


            // S;O;A;C;FREEFORM
            // G;S;A;C;DDA:RFC-822

            if (!String.IsNullOrEmpty(Givenname))
                builder.AppendFormat("G={0};", Givenname);

            if(!String.IsNullOrEmpty(Surname))
                builder.AppendFormat("S={0};",Surname);

            if (!String.IsNullOrEmpty(Organizationname))
                builder.AppendFormat("O={0};", Organizationname);

            if (!String.IsNullOrEmpty(Administrationmanagementdomain))
                builder.AppendFormat("A={0};", Administrationmanagementdomain);

            if (!String.IsNullOrEmpty(Countryname))
                builder.AppendFormat("C={0};", Countryname);

            if (!String.IsNullOrEmpty(OrganizationalUnitnames))
                builder.AppendFormat("OU={0};", OrganizationalUnitnames);

            if (!String.IsNullOrEmpty(Initials))
                builder.AppendFormat("I={0};", Initials);

            if (!String.IsNullOrEmpty(FREEFORM))
                builder.AppendFormat("FREEFORM={0};", FREEFORM);

            if (!String.IsNullOrEmpty(DDA_RFC_822))
                builder.AppendFormat("DDA:RFC-822={0};", DDA_RFC_822);
            
            return builder.ToString().TrimEnd(new char[]{';'});
        } 

        #endregion
    }
}
